﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuanLyThuVien.DataAccess;
using System.Windows.Forms;

namespace QuanLyThuVien.Business
{
    /// <summary>
    /// Lớp này sử dụng dịch vụ của lớp SachDAL trong DataAccess và cung cấp dịch vụ cho lớp Presentation
    /// </summary>
    class DauSachBUS
    {
        DauSachDAL dbSachDAL = new DauSachDAL();
        /// <summary>
        /// Thêm mới sách
        /// </summary>
        /// <param name="busSach"></param>
        public void ThemMoiSach(DauSach busSach)
        {
            if (!dbSachDAL.KiemTraDL(busSach.MaDauSach))
            {
                dbSachDAL.ThemMoiSach(busSach);
            }
            else
            {
                MessageBox.Show("Mã sách này đã tồn tại.", "QuanLyThuVien");
            }
        }

        public void SuaSach(DauSach busSach)
        {
                dbSachDAL.SuaSach(busSach);
        }

        public void XoaSach(string MaDS)
        {
                dbSachDAL.XoaSach(MaDS);
        }

        /// <summary>
        /// Load dữ liệu từ bảng CSDL tbSach lên dataGridView
        /// </summary>
        /// <param name="dg">DataGridView nhập sách</param>
        public void LayDLLenDataGridView(DataGridView dg)
        {
            dbSachDAL.LayDLLenDataGridView(dg);
        }

        public void LoadDLLenCombobox(ComboBox cb)
        {
            dbSachDAL.LoadDLLenCombobox(cb);
        }

        public string TongSach(string tongSach)
        {
          return dbSachDAL.LaySoLuongSach(tongSach);
        }

        public int LayTongSach(string maDS)
        {
           string TS= dbSachDAL.LayTongSach(maDS);
           return int.Parse(TS);
        }

        public void LayMaDSLenCB(ComboBox cb,string  TenSach)
        {
         dbSachDAL.LayMaDSLenCB(cb, TenSach);
        }

        public void LayChuyenNganhLenCB(ComboBox cb, string TenSach)
        {
            dbSachDAL.LayChuyenNganhLenCB(cb, TenSach);
        }

        public void LayMaDSLenCBTheoCN(ComboBox cb, string CN,string TenSach)
        {
            dbSachDAL.LayMaDSLenCBTheoCN(cb, CN,TenSach);
        }

        public void LoadCNLenCB(ComboBox cb)
        {
            dbSachDAL.LoadCNLenCB(cb);
        }

        public void TraCuuSachTu2TieuChi(DataGridView dg, string tentruong1, string tieuchi1, string tentruong2, string tieuchi2)
        {
            dbSachDAL.TraCuuSachTu2TieuChi(dg, tentruong1, tieuchi1, tentruong2, tieuchi2);
        }

        public void LoadLenDGThongKeSach(DataGridView dg, string NXB)
        {
            dbSachDAL.LoadLenDGThongKeSach(dg, NXB);
        }

        public void LoadLenDGTKSachTheoTG(DataGridView dg, string TenTG)
        {
            dbSachDAL.LoadLenDGTKSachTheoTG(dg, TenTG);
        }

        public void ThongKeSachConInTV(DataGridView dg)
        {
            dbSachDAL.ThongKeSachConInTV(dg);
        }

        public void ThongKeSachTon(DataGridView dg)
        {
            dbSachDAL.ThongKeSachTon(dg);
        }

        public void TimKiemSachNangCao(DataGridView dg, string DL)
        {
            dbSachDAL.TimKiemSachNangCao(dg, DL);
        }
    }
}
